"use strict";
/* Controllers  dataMetricDapanListController*/
app.controller("DataServiceController", ['$scope', '$location', '$rootScope', '$routeParams','dataListService', function ($scope, $location, $rootScope, $routeParams,dataListService) {
    var vm = $scope.vm = {};
    vm.p = {};
    vm.p.biz = $routeParams.biz;
    vm.result = {};
    vm.items=[];

    var errorFn = function (result) {
        alert(result);
    };


    $scope.renderFinish = function(){
        setTimeout(function(){
            sparkLine();
        },100);
    };
    $scope.listMetricSource = function () {
        var vm = $scope.vm;
        var params = {topic: 'topic'};
        var procFn = function (response) {
            vm.result.ms = response.ms;
            if ("000" !== response.code) {
                alert(response.message);
                return ;
            }
            vm.result.ms = response.ms;
            var data = response.data;
            if (data == null) return;
            vm.result.data = data;
            $('#list_table').bootstrapTable('load', data);

        };
        dataListService.listMetricSource(params, procFn, errorFn);
    };

    // 删除逻辑
    $scope.confirmDel = function (id) {
        vm.toDelId = id
        $('#myModal').modal('show')
    }

    $scope.initializeController = function () {
        vm.result.ms = '';
        var $resultTable = $('#list_table');
        $resultTable.bootstrapTable({
            pageList: [10, 30, 50, 100, 300, 500, 1000], pageSize: 30
        });

        $resultTable.bootstrapTable('hideColumn', 'dbMessage');
        $resultTable.bootstrapTable('hideColumn', 'dataResultDescription');

        $resultTable.bootstrapTable('hideColumn', 'indexDimension');
        $resultTable.bootstrapTable('hideColumn', 'indicatorDescription');
        $resultTable.bootstrapTable('hideColumn', 'demandSide');
        $resultTable.bootstrapTable('hideColumn', 'doc');

        $scope.listMetricSource();
    };
    $scope.initializeController();

}]);


/* Services */
app.service('dataListService', ['ajaxService', function (ajaxService) {
    this.listMetricSource = function (params, successFunction, errorFunction) {
        ajaxService.AjaxPost(params, "/star/api/basic-service/v1/data_content/listMetricServiceEntity.do", successFunction, errorFunction);
    };
}]);

function dataServiceIdOptFmt(value, row, index) {
    if (value == null) {
        return "-";
    }
    return [
        '<a  class="btn btn-primary btn-sm" href="#/star/content/data_service_detail/',row.id,'" target="_blank">详情</a> ',
        '<a  class="btn btn-primary btn-sm" href="#/star/metric2/data_service_modify/',row.id,'" target="_blank">修改</a>'
    ].join('');
}
